Data Preparation

Create Environment and set parameters

###############################################################################
## Create biologic Object for visualization                                  ##
singleCellClusterParameter <- 0.3
NtopGenes <- 2000
singleCellSeuratMtCutoff <- c(20)
singleCellSeuratNpcs4PCA <- 30
SeuratNrnaMaxFeatures <- 10000
SeuratNrnaMinFeatures <- 200
## Done                                                                      ##
###############################################################################

Set Parameters

## Setup plot collection object
VersionPdfExt <- paste0(".V", gsub("-", "", Sys.Date()), ".pdf")

if (dir.exists("/Volumes/babs/working/boeings/")){
    hpc.mount <- "/Volumes/babs/working/boeings/"
} else if (dir.exists("Y:/working/boeings/")){
    hpc.mount <- "Y:/working/boeings/"
} else if (dir.exists("/camp/stp/babs/working/boeings/")){
    hpc.mount <- "/camp/stp/babs/working/boeings/"
} else {
    hpc.mount <- ""
}

# source(
#     paste0(
#         hpc.mount,
#         "Stefan/protocol_files/github/boeings/packages/packageSourceCode/SBwebtools.pckg.r"
#     )
# )

# source(
#     paste0(
#         hpc.mount,
#         "Stefan/protocol_files/github/boeings/packages/scTools/scTools.r"
#     )
# )

source("assets/scTools.r")
source("assets/SBwebtools.pckg.r")



if (length(.libPaths()) > 2){
    .libPaths(.libPaths()[2:3])
}

library(dplyr)
library(ggplot2)
library(tidyverse)
library(tidyr)
library(knitr)
library(Seurat)
library(DT)


###############################################################################
## Create sampleDetail List                                                  ##

# type must be in c("TenX", "matrixFiles", "loomFiles", "hdf5Files")

sampleDetailList <- list(
    "NormCon" = list(
        "type" = "TenX",
        "path" = "/camp/stp/babs/inputs/sequencing/fastq/190906_K00102_0390_AHCL5KBBXY/count/SC18275/BAI253A5/outs/filtered_feature_bc_matrix",
        "singleCellClusterParameter" = singleCellClusterParameter,
        "singleCellSeuratMtCutoff" = 20,
        "singleCellSeuratNpcs4PCA" = singleCellSeuratNpcs4PCA,
        "SeuratNrnaMaxFeatures" = SeuratNrnaMaxFeatures,
        "SeuratNrnaMinFeatures" = SeuratNrnaMinFeatures,
        "limsId"= "BAI253A5",
        "singleCellChemistry" = NULL,
        "singleCellCellrangerVersion" = NULL, 
        "machine" = NULL
    ),
    "HypCon" = list(
        "type" = "TenX",
        "path" = "/camp/stp/babs/inputs/sequencing/fastq/190906_K00102_0390_AHCL5KBBXY/count/SC18275/BAI253A6/outs/filtered_feature_bc_matrix",
        "singleCellClusterParameter" = singleCellClusterParameter,
        "singleCellSeuratMtCutoff" = 20,
        "singleCellSeuratNpcs4PCA" = singleCellSeuratNpcs4PCA,
        "SeuratNrnaMaxFeatures" = SeuratNrnaMaxFeatures,
        "SeuratNrnaMinFeatures" = SeuratNrnaMinFeatures,
        "limsId"= "BAI253A6",
        "singleCellChemistry" = NULL,
        "singleCellCellrangerVersion" = NULL, 
        "machine" = NULL
    ),
    
    "NormPrad" = list(
        "type" = "TenX",
        "path" = "/camp/stp/babs/inputs/sequencing/fastq/190906_K00102_0390_AHCL5KBBXY/count/SC18275/BAI253A7/outs/filtered_feature_bc_matrix",
        "singleCellClusterParameter" = singleCellClusterParameter,
        "singleCellSeuratMtCutoff" = 20,
        "singleCellSeuratNpcs4PCA" = singleCellSeuratNpcs4PCA,
        "SeuratNrnaMaxFeatures" = SeuratNrnaMaxFeatures,
        "SeuratNrnaMinFeatures" = SeuratNrnaMinFeatures,
        "limsId"= "BAI253A7",
        "singleCellChemistry" = NULL,
        "singleCellCellrangerVersion" = NULL, 
        "machine" = NULL
    ),
    "HypPrad" = list(
        "type" = "TenX",
        "path" = "/camp/stp/babs/inputs/sequencing/fastq/190906_K00102_0390_AHCL5KBBXY/count/SC18275/BAI253A8/outs/filtered_feature_bc_matrix",
        "singleCellClusterParameter" = singleCellClusterParameter,
        "singleCellSeuratMtCutoff" = 20,
        "singleCellSeuratNpcs4PCA" = singleCellSeuratNpcs4PCA,
        "SeuratNrnaMaxFeatures" = SeuratNrnaMaxFeatures,
        "SeuratNrnaMinFeatures" = SeuratNrnaMinFeatures,
        "limsId"= "BAI253A8",
        "singleCellChemistry" = NULL,
        "singleCellCellrangerVersion" = NULL, 
        "machine" = NULL
    ),
    "NormAZ" = list(
        "type" = "TenX",
        "path" = "/camp/stp/babs/inputs/sequencing/fastq/190906_K00102_0390_AHCL5KBBXY/count/SC18275/BAI253A9/outs/filtered_feature_bc_matrix",
        "singleCellClusterParameter" = singleCellClusterParameter,
        "singleCellSeuratMtCutoff" = 10,
        "singleCellSeuratNpcs4PCA" = singleCellSeuratNpcs4PCA,
        "SeuratNrnaMaxFeatures" = SeuratNrnaMaxFeatures,
        "SeuratNrnaMinFeatures" = SeuratNrnaMinFeatures,
        "limsId"= "BAI253A9",
        "singleCellChemistry" = NULL,
        "singleCellCellrangerVersion" = NULL, 
        "machine" = NULL
    ),
    "HypAZ" = list(
        "type" = "TenX",
        "path" = "/camp/stp/babs/inputs/sequencing/fastq/190906_K00102_0390_AHCL5KBBXY/count/SC18275/BAI253A10/outs/filtered_feature_bc_matrix",
        "singleCellClusterParameter" = singleCellClusterParameter,
        "singleCellSeuratMtCutoff" = 10,
        "singleCellSeuratNpcs4PCA" = singleCellSeuratNpcs4PCA,
        "SeuratNrnaMaxFeatures" = SeuratNrnaMaxFeatures,
        "SeuratNrnaMinFeatures" = SeuratNrnaMinFeatures,
        "limsId"= "BAI253A10",
        "singleCellChemistry" = NULL,
        "singleCellCellrangerVersion" = NULL, 
        "machine" = NULL
    )
)

##                                                                           ##
###############################################################################

###############################################################################
## dbDetailList                                                              ##
dbDetailList <- list(
    "primDataDB" = "agl_data",
    "ref.cat.db" = "reference_categories_db_new",
     "db.user" = "boeingS",
     "host" = "10.27.241.82"
)
## End dbDetailList                                                          ##
###############################################################################

###############################################################################
## Project detail list                                                       ##
projectDetailList <- list(
    "folder" = "goulda/andrew.bailey/327A_scRNASeq_Tumor_Disc_Development_cell_lines__part_B_SC18275/",
    "sra.id.vector" = "",
    "gse.id.vector" = "",
    "asf.id" = "SC18275",
    "experiment.type" = "sc_rna_seq",   
    "species" = "homo_sapiens", 
    "release" = "release-89", 
    "project_id" = "agl327A",
    "labname" = "Gould",
    "timecourse.units" = "",
    "count.table.headline" = "lg10 Expr for all Samples",
    "count.table.sidelabel" = "lg10 Expr",
    "heamap.headline.text" = "Heatmap: Row-averaged Expr"
)
## End project detail list                                                   ##
###############################################################################


###############################################################################
## Project detail list                                                       ##
scDetailList <- list(
    "NtopGenes" =  NtopGenes,
    "singleCellClusterParameter" = singleCellClusterParameter,
    "singleCellClusterString" = paste0("integrated_snn_res.", singleCellClusterParameter),
    "scIntegrationMethod" = "SCT", # "SCT" or "standard"
    "scNintegrationFeatures" = 3000,
    "primReduction" = "umap"
)
## End project detail list                                                   ##
###############################################################################

###############################################################################
## Reference Table List                                                      ##
referenceTableList = list(
    "Hallmark Signatures" = "mysigdb_h_hallmarks",
    "Pathways" = "mysigdb_c2_1329_canonical_pathways",
    "GO-BP" = "mysigdb_c5_BP",                               
    "GO-MF" = "mysigdb_c5_MF",
    "TF Motifs" = "TRANSFAC_and_JASPAR_PWMs",
    "Protein Complexes" = "networkcategories",
    "GO-BP" = "GO_Biological_Process_2017",
    "Immunologic Signatures" = "mysigdb_c7_immunologic_signatures",
    "LINCS Down" = "LINCS_L1000_Chem_Pert_down",
    "LINCS Up" = "LINCS_L1000_Chem_Pert_up",
    "Allen Brain Atlas" = "Allen_Brain_Atlas",
    "Cell Type Signatures" = "mysigdb_sc_sig",
    "Cell Type Signatures" = "cibersort_L22"
)

    # mysigdb_sc_sig
    # cibersort_L22
    # Allen_Brain_Atlas                            |
    # CORUM                                        |
    # ChEA_2016                                    |
    # DEPOD_phosphatase_substrates                 |
    # ENCODE_TF_ChIP_seq_2015                      |
    # GO_Biological_Process_2017                   |
    #LINCS_L1000_Chem_Pert_down                   |
    #LINCS_L1000_Chem_Pert_down_backup            |
    # LINCS_L1000_Chem_Pert_up                     |
    # LINCS_L1000_Chem_Pert_up_backup              |
    # NCBI_homologene_table                        |
    # Old_CMAP_down                                |
    # Old_CMAP_up                                  |
    # SGP_from_GEO_up_down_combined                |
    # SILAC_Phosphoproteomics                      |
    # TRANSFAC_and_JASPAR_PWMs                     |
    # UK_Biobank_GWAS                              |
    # ag_lab_categories                            |
    # as_lab_categories                            |
    # bader_lab_hESC_reference                     |
    # bt_lab_categories                            |
    # cat_selection_default                        |
    # cs_lab_categories                            |
    # da_lab_categories                            |
    # es_lab_categories                            |
    # esl111_cat_reference_db_table                |
    # et_lab_categories                            |
    # exploration_categories                       |
    # fg_lab_categories                            |
    # fi_lab_categories                            |
    # gk_lab_categories                            |
    # innateDB_PPI                                 |
    # jb_lab_categories                            |
    # js_lab_categories                            |
    # kn_lab_categories                            |
    # mysigdb_c1_positional                        |
    # mysigdb_c2_1329_canonical_pathways           |
    # mysigdb_c2_KEGG                              |
    # mysigdb_c2_REACTOME                          |
    # mysigdb_c2_biocarta                          |
    # mysigdb_c2_chemical_and_genetic_pertubations |
    # mysigdb_c3_TF_targets                        |
    # mysigdb_c3_miRNA_targets 
# et_lab_categories                            |
# | exploration_categories                       |
# | fg_lab_categories                            |
# | fgl391_cat_reference_db_table                |
# | fi_lab_categories                            |
# | gk_lab_categories                            |
# | innateDB_PPI                                 |
# | jb_lab_categories                            |
# | js_lab_categories                            |
# | kn_lab_categories                            |
# | mysigdb_c1_positional                        |
# | mysigdb_c2_1329_canonical_pathways           |
# | mysigdb_c2_KEGG                              |
# | mysigdb_c2_REACTOME                          |
# | mysigdb_c2_biocarta                          |
# | mysigdb_c2_chemical_and_genetic_pertubations |
# | mysigdb_c3_TF_targets                        |
# | mysigdb_c3_miRNA_targets                     |
# | mysigdb_c5_BP                                |
# | mysigdb_c5_CC                                |
# | mysigdb_c5_MF                                |
# | mysigdb_c6_oncogenic_signatures              |
# | mysigdb_c7_immunologic_signatures            |
# | mysigdb_h_hallmarks                          |
# | networkcategories                            |
# | nl_lab_categories                            |
# | pa_lab_categories                            |
# | pb_lab_categories                            |
# | pfam_interpro                                |
# | pp_lab_categories                            |
# | project_db_table                             |
# | project_db_table_backup                      |
# | project_description_table                    |
# | pt_lab_categories                            |
# | re_lab_categories                            |
# | reference_categories_db_new                  |
# | rl_lab_categories                            |
# | sb_lab_categories                            |
# | sc_lab_categories                            |
# | sl_lab_categories                            |
# | sl_lab_categories_backup                     |
# | ss_lab_categories                            |
# | st_lab_categories                            |
# | temp_categories                              |
# | vp_lab_categories                            |
# | vt_lab_categories

## Done                                                                      ##
###############################################################################

# Species has to be "mus_musculus", "homo_sapiens", "danio_rerio" 
# release-86, release-89

Obio = new(
    "bioLOGIC",
    dbDetailList = dbDetailList,        
    projectDetailList = projectDetailList,
    sampleDetailList = sampleDetailList, 
    referenceTableList = referenceTableList,
    parameterList = list(
        "lab.categories.table" = "ag_lab_categories", # default NULL
        "folder" = projectDetailList$folder,
        "sra.id.vector" = "",
        "gse.id.vector" = "",
       "lims.id"= "",
        "asf.id" = "",
        "machine" = NULL,
        "experiment.type" = "sc_rna_seq",   
        "species" = projectDetailList$species, 
        "release" = "release-89", 
        "project_id" = projectDetailList$project_id,
        "labname" = projectDetailList$labname,
        "db.user" = "boeingS",
        "host" = "10.27.241.82",
        "timecourse.units" = "",
        "count.table.headline" = "lg10 Expr for all Samples",
        "count.table.sidelabel" = "lg10 Expr",
        "heamap.headline.text" = "Heatmap: Row-averaged Expr",
        "loadR" = "module purge;source /camp/stp/babs/working/software/modulepath_new_software_tree_2018-08-13;module load pandoc/2.2.3.2-foss-2016b;ml R/3.6.0-foss-2016b-BABS;R;",
        "pathToSeqStorageFolder" = NULL,
        "matrixFiles" = NULL,
        "loomFiles" = NULL,
        "addFullTPMtable" = FALSE,
        "hpcMount" = "",
        "parallelProcessing" = FALSE,
        "timeseries" = TRUE,
        "NtopGenes" =  NtopGenes,
        "singleCellClusterParameter" = singleCellClusterParameter,
        "singleCellClusterString" = paste0("integrated_snn_res.", singleCellClusterParameter),
        "singleCellPercExpressedMinCutOff" = 10,
        "singleCellTranscriptome"="GRCh38",
        "singleCellChemistry" = NULL,
        "singleCellCellrangerVersion" = NULL, 
        "singleCellSeuratMtCutoff" = c(20,20,20,20,10,10),
        "singleCellSeuratNpcs4PCA" = singleCellSeuratNpcs4PCA,
        "scIntegrationMethod" = "SCT", # "SCT" or "standard"
        "scNintegrationFeatures" = scDetailList$scNintegrationFeatures,
        "SeuratNrnaMaxFeatures" = SeuratNrnaMaxFeatures,
        "SeuratNrnaMinFeatures" = SeuratNrnaMinFeatures,
        "primReduction" = "umap",
        "qcReports" = list(),
        "catRefFile" = "/camp/stp/babs/working/boeings/Projects/goulda/andrew.bailey/315A_scRNASeq_Tumor_Disc_Development_single_cell_SC18275/basedata/agl315.AUC.cat.reference.table.txt",
        referenceTableList = referenceTableList
    )
)


Obio <- setMountingPoint(Obio)
Obio <- setAnalysisPaths(Obio)
Obio <- setCrickGenomeAndGeneNameTable(Obio)
Obio <- createAnalysisFolders(
    Obio,
    baseDir="/camp/stp/babs/working/boeings/Projects/",
    localBaseDir = paste0(hpc.mount, "Projects/")
)
Obio <- setDataBaseParameters(Obio)


Obio@parameterList[["reportFigDir"]] <- paste0(Obio@parameterList$localWorkDir,Obio@parameterList$project_id, "/report_figures/")

####

FN <- paste0(hpc.mount, "Projects/reference_data/documentation/BC.parameters.txt")
dbTable <- read.delim(
    FN, 
    sep = "\t",
    stringsAsFactors = F
)

db.pwd <- as.vector(dbTable[1,1])

## Create outputfolders ##
if (!dir.exists(paste0(Obio@parameterList$localWorkDir,Obio@parameterList$project_id))){
    dir.create(paste0(Obio@parameterList$localWorkDir,Obio@parameterList$project_id))
}

if (!dir.exists(Obio@parameterList$reportFigDir)){
    dir.create(Obio@parameterList$reportFigDir)
}


figureCount <- 1

## Load R module load R/3.5.1-foss-2018b ##
#setwd(Obio@parameterList$localWorkDir)
### Will save Obio object here, so it can be re-used with different parameters
save(Obio, 
     file = paste0(
         Obio@parameterList$localWorkDir,
         Obio@parameterList$project_id,
         ".bioLOGIC.Robj"
     )
)

print("R bioLOGIC single cell object initialized.")

QC Section

Create First figure

Create QC Table

tableCreated <- FALSE
sampleNames <- names(Obio@sampleDetailList)

for (i in 1:length(sampleNames)){
    if (Obio@sampleDetailList[[sampleNames[i]]]$type == "TenX"){
        baseFN <- Obio@sampleDetailList[[sampleNames[i]]]$path
        summaryFN <- gsub("filtered_feature_bc_matrix", "metrics_summary.csv", baseFN)
        if (file.exists(summaryFN)){
            dfTemp <- read.csv(summaryFN)
            dfTemp[["sampleName"]] <- sampleNames[i]
            if (!tableCreated){
                tableCreated = TRUE
                dfRes <- dfTemp
            } else {
                dfRes <- rbind(
                    dfRes,
                    dfTemp
                )
            }
        }
    }
}

if (exists("dfRes")){
dfRes <- data.frame(t(dfRes))
colVec <- as.vector(t(dfRes["sampleName",]))
names(dfRes) <- colVec

dfRes <- dfRes[!(row.names(dfRes) %in% c("sampleName")),]
dfRes[["Parameter"]] <- row.names(dfRes)
row.names(dfRes) <- NULL
colVec <- c("Parameter", colVec)
dfRes <- dfRes[,colVec]
dfRes$Parameter <- gsub("[.]", " ", dfRes$Parameter)


###############################################################################
## Write table to Excel File                                                 ##

createXLSXoutput(
    dfTable = dfRes,
    outPutFN = paste0(Obio@parameterList$outputDir, "/",Obio@parameterList$project_id, "_QC_Parameter_Table.xlsx"),
    tableName = paste0(Obio@parameterList$project_id, "_QC_Parameter_Table")
)

## Done creating Excel output table                                          ##
###############################################################################

Obio@parameterList$reportTableDir <- gsub("report_figures", "report_tables",Obio@parameterList$reportFigDir)

if (!dir.exists(Obio@parameterList$reportTableDir)){
    dir.create(Obio@parameterList$reportTableDir)
}

FNbase <- paste0(Obio@parameterList$project_id, "_QC_Parameter_Table.xlsx")
FN <- paste0(Obio@parameterList$reportTableDir, FNbase)
FNrel <- paste0("report_tables/", FNbase)


tabDownloadLink <- paste0("The quality measures table can be downloaded [here](",FNrel,")")

tabLegend = paste0(
    "**Table: ** QC Parameters for all 10X single-cell samples in this experiment. ",
    tabDownloadLink
)

chnkVec <- paste0(
        #"#### ", names(dtList),
        "\n```{r QC_datatable, results='asis', echo=F, eval=TRUE, warning=FALSE, fig.cap='",
        tabLegend,"'}\n",
        "\n",
        "\n datatable(dfRes,rownames = FALSE,  escape = FALSE)",
        "\n cat(  '\n')",
        "\n\n\n```\n"   
    )
}    
## Done creating one table per cluster                                      ##
##############################################################################
if (exists("dfRes")){
    cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))
}

Table: QC Parameters for all 10X single-cell samples in this experiment. The quality measures table can be downloaded here

Turn QC Table into figures

CellRanger QC

###############################################################################
## Create Cell Ranger QC Plots                                               ##
if (exists("dfRes")){
## Add if clause to check 10X
resList <- doCRplots(
    obj = Obio,
    figureCount = figureCount,
    VersionPdfExt = VersionPdfExt,
    tocSubLevel = 4,
    dotsize = 0.5
) 

plotListQC1 <- resList$plotListQC1
chnkVec <- resList$chnkVec
figureCount <- resList$figureCount
}

## Done create cellRanger QC plots                                           ##
###############################################################################
if (exists("dfRes")){
cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))
}

NormCon

**Figure 1:**  CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure [here](report_figures/cellranger.result.NormCon.V20200828.pdf).

Figure 1: CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure here.

HypCon

**Figure 2:**  CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure [here](report_figures/cellranger.result.HypCon.V20200828.pdf).

Figure 2: CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure here.

NormPrad

**Figure 3:**  CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure [here](report_figures/cellranger.result.NormPrad.V20200828.pdf).

Figure 3: CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure here.

HypPrad

**Figure 4:**  CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure [here](report_figures/cellranger.result.HypPrad.V20200828.pdf).

Figure 4: CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure here.

NormAZ

**Figure 5:**  CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure [here](report_figures/cellranger.result.NormAZ.V20200828.pdf).

Figure 5: CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure here.

HypAZ

**Figure 6:**  CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure [here](report_figures/cellranger.result.HypAZ.V20200828.pdf).

Figure 6: CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure here.

All

**Figure 7:**  CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure [here](report_figures/cellranger.result.All.V20200828.pdf).

Figure 7: CellRanger quality assessment. Green cells are considered for further analysis. Download a pdf of this figure here.

Determining Parameters for Subsequent Single-cell Analysis

Make Sample List for single-sample assessment

SampleList <- createSampleListQC(
    obj = Obio
)

Create PercentMT Historgrams Plots

###############################################################################
## Do percent mt plots                                                       ##
resList <- doPercMT_plotSL(
        SampleList = SampleList,
        obj = Obio,
        figureCount = figureCount,
        VersionPdfExt = ".pdf",
        tocSubLevel = 4
)


plotListRF <- resList$plotListRF
chnkVec <- resList$chnkVec
figureCount <- resList$figureCount

## Done create cellRanger QC plots                                           ##
###############################################################################
cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))

Hist_MT_NormCon

**Figure 8C:** Histogram depicting percent mitochondrial genes for each sample NormCon. Download a pdf of this figure [here](report_figures/Historgram.MTNormCon.pdf).

Figure 8C: Histogram depicting percent mitochondrial genes for each sample NormCon. Download a pdf of this figure here.

Hist_MT_HypCon

**Figure 9C:** Histogram depicting percent mitochondrial genes for each sample HypCon. Download a pdf of this figure [here](report_figures/Historgram.MTHypCon.pdf).

Figure 9C: Histogram depicting percent mitochondrial genes for each sample HypCon. Download a pdf of this figure here.

Hist_MT_NormPrad

**Figure 10C:** Histogram depicting percent mitochondrial genes for each sample NormPrad. Download a pdf of this figure [here](report_figures/Historgram.MTNormPrad.pdf).

Figure 10C: Histogram depicting percent mitochondrial genes for each sample NormPrad. Download a pdf of this figure here.

Hist_MT_HypPrad

**Figure 11C:** Histogram depicting percent mitochondrial genes for each sample HypPrad. Download a pdf of this figure [here](report_figures/Historgram.MTHypPrad.pdf).

Figure 11C: Histogram depicting percent mitochondrial genes for each sample HypPrad. Download a pdf of this figure here.

Hist_MT_NormAZ

**Figure 12C:** Histogram depicting percent mitochondrial genes for each sample NormAZ. Download a pdf of this figure [here](report_figures/Historgram.MTNormAZ.pdf).

Figure 12C: Histogram depicting percent mitochondrial genes for each sample NormAZ. Download a pdf of this figure here.

Hist_MT_HypAZ

**Figure 13C:** Histogram depicting percent mitochondrial genes for each sample HypAZ. Download a pdf of this figure [here](report_figures/Historgram.MTHypAZ.pdf).

Figure 13C: Histogram depicting percent mitochondrial genes for each sample HypAZ. Download a pdf of this figure here.

Create RNA Feature Historgrams Plots

###############################################################################
## Do percent mt plots                                                       ##
resList <- doRNAfeat_plotSL(
        SampleList,
        obj = Obio,
        figureCount = figureCount,
        VersionPdfExt = ".pdf",
        tocSubLevel = 4
)

plotListRF <- resList$plotListRF
chnkVec <- resList$chnkVec
figureCount <- resList$figureCount

## Done create cellRanger QC plots                                           ##
###############################################################################
cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))

NormCon

**Figure 14C:** Histogram depicting genes found per cell/nuclei for sample NormCon. Download a pdf of this figure [here](report_figures/Historgram.GLNormCon.pdf).

Figure 14C: Histogram depicting genes found per cell/nuclei for sample NormCon. Download a pdf of this figure here.

HypCon

**Figure 15C:** Histogram depicting genes found per cell/nuclei for sample HypCon. Download a pdf of this figure [here](report_figures/Historgram.GLHypCon.pdf).

Figure 15C: Histogram depicting genes found per cell/nuclei for sample HypCon. Download a pdf of this figure here.

NormPrad

**Figure 16C:** Histogram depicting genes found per cell/nuclei for sample NormPrad. Download a pdf of this figure [here](report_figures/Historgram.GLNormPrad.pdf).

Figure 16C: Histogram depicting genes found per cell/nuclei for sample NormPrad. Download a pdf of this figure here.

HypPrad

**Figure 17C:** Histogram depicting genes found per cell/nuclei for sample HypPrad. Download a pdf of this figure [here](report_figures/Historgram.GLHypPrad.pdf).

Figure 17C: Histogram depicting genes found per cell/nuclei for sample HypPrad. Download a pdf of this figure here.

NormAZ

**Figure 18C:** Histogram depicting genes found per cell/nuclei for sample NormAZ. Download a pdf of this figure [here](report_figures/Historgram.GLNormAZ.pdf).

Figure 18C: Histogram depicting genes found per cell/nuclei for sample NormAZ. Download a pdf of this figure here.

HypAZ

**Figure 19C:** Histogram depicting genes found per cell/nuclei for sample HypAZ. Download a pdf of this figure [here](report_figures/Historgram.GLHypAZ.pdf).

Figure 19C: Histogram depicting genes found per cell/nuclei for sample HypAZ. Download a pdf of this figure here.

Plot UMAP Per Sample

###############################################################################
## Do percent mt plots                                                       ##
resList <- doUMAP_plotSL(
        SampleList,
        obj = Obio,
        figureCount = figureCount,
        VersionPdfExt = ".pdf",
        tocSubLevel = 4,
        dotsize = 0.5
)

plotListSQCUMAP <- resList$plotListSQCUMAP
chnkVec <- resList$chnkVec
figureCount <- resList$figureCount

## Done create cellRanger QC plots                                           ##
###############################################################################
cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))

U_NormCon

**Figure 20:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.U_NormCon.pdf).

Figure 20: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

U_HypCon

**Figure 21:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.U_HypCon.pdf).

Figure 21: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

U_NormPrad

**Figure 22:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.U_NormPrad.pdf).

Figure 22: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

U_HypPrad

**Figure 23:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.U_HypPrad.pdf).

Figure 23: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

U_NormAZ

**Figure 24:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.U_NormAZ.pdf).

Figure 24: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

U_HypAZ

**Figure 25:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.U_HypAZ.pdf).

Figure 25: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

Plot Per Sample Doublet Estimate

###############################################################################
## Do percent mt plots                                                       ##
resList <-  doDF_plotSL(
        SampleList,
        obj = Obio,
        figureCount = figureCount,
        VersionPdfExt = ".pdf",
        tocSubLevel = 4,
        dotsize = 0.5
)
    
 

plotListDF <- resList$plotListDF
chnkVec <- resList$chnkVec
figureCount <- resList$figureCount
Obio@dataTableList[["DF_resultlist"]] <- resList$addList
        
## Done create cellRanger QC plots                                           ##
###############################################################################
cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))

NormCon

**Figure 26:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.NormCon.pdf).

Figure 26: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

HypCon

**Figure 27:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.HypCon.pdf).

Figure 27: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

NormPrad

**Figure 28:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.NormPrad.pdf).

Figure 28: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

HypPrad

**Figure 29:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.HypPrad.pdf).

Figure 29: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

NormAZ

**Figure 30:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.NormAZ.pdf).

Figure 30: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

HypAZ

**Figure 31:**  Sample-level UMAP plot for QC purposes. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.HypAZ.pdf).

Figure 31: Sample-level UMAP plot for QC purposes. Download a pdf of this figure here.

Plot Per Sample MT Percentage

###############################################################################
## Do percent mt plots                                                       ##

resList <- doUMAP_plot_percMT(
    SampleList,
    obj =  Obio,
    figureCount = figureCount,
    VersionPdfExt = ".pdf",
    tocSubLevel = 4,
    dotsize = 0.5
)
 

plotListUMT <- resList$plotListUMT
chnkVec <- resList$chnkVec
figureCount <- resList$figureCount

        
## Done create cellRanger QC plots                                           ##
###############################################################################
cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))

UMT_NormCon

**Figure 32:**  Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.perMTUMT_NormCon.pdf).

Figure 32: Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure here.

UMT_HypCon

**Figure 33:**  Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.perMTUMT_HypCon.pdf).

Figure 33: Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure here.

UMT_NormPrad

**Figure 34:**  Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.perMTUMT_NormPrad.pdf).

Figure 34: Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure here.

UMT_HypPrad

**Figure 35:**  Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.perMTUMT_HypPrad.pdf).

Figure 35: Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure here.

UMT_NormAZ

**Figure 36:**  Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.perMTUMT_NormAZ.pdf).

Figure 36: Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure here.

UMT_HypAZ

**Figure 37:**  Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.perMTUMT_HypAZ.pdf).

Figure 37: Sample-level UMAP plot for QC purposes. Colored by the percent of mitochondrial gene expression per cell. Download a pdf of this figure here.

Plot Per Sample nFeatures RNA

###############################################################################
## Do percent mt plots                                                       ##

resList <- doUMAP_plot_nFeatRNA(
    SampleList,
    obj =  Obio,
    figureCount = figureCount,
    VersionPdfExt = ".pdf",
    tocSubLevel = 4,
    dotsize = 0.5
)
 

plotListNC <- resList$plotListNC
chnkVec <- resList$chnkVec
figureCount <- resList$figureCount

        
## Done create cellRanger QC plots                                           ##
###############################################################################
cat(paste(knit(text = chnkVec, quiet = T), collapse = '\n'))

NC_NormCon

**Figure 38:**  Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.nFeatRNANC_NormCon.pdf).

Figure 38: Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure here.

NC_HypCon

**Figure 39:**  Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.nFeatRNANC_HypCon.pdf).

Figure 39: Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure here.

NC_NormPrad

**Figure 40:**  Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.nFeatRNANC_NormPrad.pdf).

Figure 40: Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure here.

NC_HypPrad

**Figure 41:**  Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.nFeatRNANC_HypPrad.pdf).

Figure 41: Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure here.

NC_NormAZ

**Figure 42:**  Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.nFeatRNANC_NormAZ.pdf).

Figure 42: Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure here.

NC_HypAZ

**Figure 43:**  Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure [here](report_figures/Sample.level.UMAP.nFeatRNANC_HypAZ.pdf).

Figure 43: Sample-level UMAP plot for QC purposes. Colored by the nFeatureRNA number. Download a pdf of this figure here.

### Will save Obio object here, so it can be re-used with different parameters
save(Obio, 
     file = paste0(
         Obio@parameterList$localWorkDir,
         Obio@parameterList$project_id,
         ".bioLOGIC.Robj"
     )
)

print("R bioLOGIC single cell object initialized.")
### Will save Obio object here, so it can be re-used with different parameters
save(SampleList, 
     file = paste0(
         Obio@parameterList$localWorkDir,
         Obio@parameterList$project_id,
         "SampleList.Robj"
     )
)

print("R bioLOGIC single cell object initialized.")

Most up/down-regulated genes

Cluster gene set enrichment

Documentation

sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: CentOS Linux 7 (Core)
## 
## Matrix products: default
## BLAS:   /camp/apps/misc/stp/babs/manual/software/r/R-3.6.0-foss-2016b/lib64/R/lib/libRblas.so
## LAPACK: /camp/apps/misc/stp/babs/manual/software/r/R-3.6.0-foss-2016b/lib64/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_GB.utf-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB.utf-8        LC_COLLATE=en_GB.utf-8    
##  [5] LC_MONETARY=en_GB.utf-8    LC_MESSAGES=en_GB.utf-8   
##  [7] LC_PAPER=en_GB.utf-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_GB.utf-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
##  [1] grid      parallel  stats4    stats     graphics  grDevices utils    
##  [8] datasets  methods   base     
## 
## other attached packages:
##  [1] sctransform_0.2.1           KernSmooth_2.23-15         
##  [3] fields_10.3                 maps_3.3.0                 
##  [5] spam_2.5-1                  dotCall64_1.0-0            
##  [7] DoubletFinder_2.0.3         scales_1.1.1               
##  [9] RColorBrewer_1.1-2          mixtools_1.2.0             
## [11] openxlsx_4.1.5              DT_0.14                    
## [13] Seurat_3.1.5                knitr_1.29                 
## [15] forcats_0.5.0               stringr_1.4.0              
## [17] purrr_0.3.4                 readr_1.3.1                
## [19] tidyr_1.1.0                 tibble_3.0.1               
## [21] tidyverse_1.3.0             ggplot2_3.3.2              
## [23] dplyr_1.0.0                 DESeq2_1.24.0              
## [25] SummarizedExperiment_1.14.1 DelayedArray_0.10.0        
## [27] BiocParallel_1.18.1         matrixStats_0.56.0         
## [29] Biobase_2.44.0              GenomicRanges_1.36.1       
## [31] GenomeInfoDb_1.20.0         IRanges_2.18.3             
## [33] S4Vectors_0.22.1            BiocGenerics_0.30.0        
## 
## loaded via a namespace (and not attached):
##   [1] readxl_1.3.1           backports_1.1.8        Hmisc_4.4-0           
##   [4] plyr_1.8.6             igraph_1.2.5           lazyeval_0.2.2        
##   [7] splines_3.6.0          crosstalk_1.1.0.1      listenv_0.8.0         
##  [10] digest_0.6.25          htmltools_0.5.0        fansi_0.4.1           
##  [13] magrittr_1.5           checkmate_2.0.0        memoise_1.1.0         
##  [16] cluster_2.0.8          ROCR_1.0-11            globals_0.12.5        
##  [19] annotate_1.62.0        modelr_0.1.8           jpeg_0.1-8.1          
##  [22] colorspace_1.4-1       blob_1.2.1             rvest_0.3.5           
##  [25] rappdirs_0.3.1         ggrepel_0.8.2          haven_2.3.1           
##  [28] xfun_0.15              crayon_1.3.4           RCurl_1.98-1.2        
##  [31] jsonlite_1.7.0         genefilter_1.66.0      survival_3.2-3        
##  [34] zoo_1.8-8              ape_5.4                glue_1.4.1            
##  [37] gtable_0.3.0           zlibbioc_1.30.0        XVector_0.24.0        
##  [40] leiden_0.3.3           kernlab_0.9-29         future.apply_1.6.0    
##  [43] DBI_1.1.0              Rcpp_1.0.4.6           viridisLite_0.3.0     
##  [46] xtable_1.8-4           htmlTable_2.0.0        reticulate_1.16       
##  [49] rsvd_1.0.3             foreign_0.8-71         bit_1.1-15.2          
##  [52] Formula_1.2-3          tsne_0.1-3             htmlwidgets_1.5.1     
##  [55] httr_1.4.1             acepack_1.4.1          ellipsis_0.3.1        
##  [58] ica_1.0-2              farver_2.0.3           pkgconfig_2.0.3       
##  [61] XML_3.99-0.3           uwot_0.1.8             nnet_7.3-12           
##  [64] dbplyr_1.4.4           locfit_1.5-9.4         labeling_0.3          
##  [67] reshape2_1.4.4         tidyselect_1.1.0       rlang_0.4.6           
##  [70] AnnotationDbi_1.46.1   munsell_0.5.0          cellranger_1.1.0      
##  [73] tools_3.6.0            cli_2.0.2              generics_0.0.2        
##  [76] RSQLite_2.2.0          broom_0.5.6            ggridges_0.5.2        
##  [79] evaluate_0.14          yaml_2.2.1             bit64_0.9-7           
##  [82] fs_1.4.2               fitdistrplus_1.1-1     zip_2.0.4             
##  [85] RANN_2.6.1             pbapply_1.4-2          future_1.17.0         
##  [88] nlme_3.1-139           xml2_1.3.2             compiler_3.6.0        
##  [91] rstudioapi_0.11        plotly_4.9.2.1         png_0.1-7             
##  [94] reprex_0.3.0           geneplotter_1.62.0     stringi_1.4.6         
##  [97] highr_0.8              RSpectra_0.16-0        lattice_0.20-38       
## [100] Matrix_1.2-18          vctrs_0.3.1            pillar_1.4.4          
## [103] lifecycle_0.2.0        lmtest_0.9-37          RcppAnnoy_0.0.16      
## [106] data.table_1.12.8      cowplot_1.0.0          bitops_1.0-6          
## [109] irlba_2.3.3            patchwork_1.0.1        R6_2.4.1              
## [112] latticeExtra_0.6-29    gridExtra_2.3          codetools_0.2-16      
## [115] MASS_7.3-51.4          assertthat_0.2.1       withr_2.2.0           
## [118] GenomeInfoDbData_1.2.1 hms_0.5.3              rpart_4.1-15          
## [121] rmarkdown_2.3          segmented_1.2-0        Rtsne_0.15            
## [124] lubridate_1.7.9        base64enc_0.1-3

  1. The Francis Crick Institute, ↩︎